package com.net.controller;

import com.net.domain.User;
import com.net.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created by zhang yufei on 2017/12/3.
 */
@Controller
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private BaseService baseService;

    @RequestMapping("/login")
    public String Login(HttpServletRequest request, HttpServletResponse response){
        return "/login";
    }

    @RequestMapping("/log")
    public String log(HttpServletRequest request, HttpServletResponse response){
        String name=request.getParameter("name");
        String password=request.getParameter("password");
        User user=baseService.getUser(name,password);
        if(user!=null){
            HttpSession session=request.getSession();
            session.setAttribute("user",user);
            return "/index";
        }
        else{
            return "redirect:/login/login";
        }
    }

}
